package com.sdi.acciones;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sdi.business.UserService;
import com.sdi.business.exception.BusinessException;
import com.sdi.business.exception.EntityAlreadyExistsException;
import com.sdi.infrastructure.Factories;
import com.sdi.model.User;

public class RegistrarAction implements Action{

	@Override
	public String execute(HttpServletRequest request,
			HttpServletResponse response,ServletContext context) {
		
		UserService service;
		User user=new User();
		service = Factories.services.createUserService();
		user.setIdUser((String) request.getParameter("nickR"));
		user.setEmail((String) request.getParameter("emailR"));
		user.setNombre((String) request.getParameter("nombreR"));
		user.setApellidos((String) request.getParameter("apellidosR"));
		user.setPassword((String) request.getParameter("passR"));
		user.setActivada(0);
		
		
		try {
		
			/*if(user.getPassword()!=request.getParameter("passRepetida")){
				
				return "FRACASO";
			}*/
			service.saveUser(user);
			
			return "EXITO";
			
			
		} catch (BusinessException be) {
		
			return "FRACASO";

			
		} catch (RuntimeException e) {
			return "FRACASO";
			
		
		} catch (EntityAlreadyExistsException e) {
			return "FRACASO";
		}
		
		
		
	}

}
